package com.xbongbong.paas.factory;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.handle.*;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 操作方式工厂类
 * @author 吴峰
 * @version v1.0
 * @date 2020/3/27 11:22
 * @since v1.0
 */
@Component
public class OptionFactory {

    private final static Map<Integer, AbstractOptionHandle> WEB_DATA_ANALYSIS_HANDLE_MAP = new ConcurrentHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);

    @Resource
    private CustomerOptionHandle customerOptionHandle;
    @Resource
    private ContractOptionHandle contractOptionHandle;
    @Resource
    private ProductOptionHandle productOptionHandle;
    @Resource
    private PaymentOptionHandle paymentOptionHandle;
    @Resource
    private ProductSerialOptionHandle productSerialOptionHandle;
    @Resource
    private ClueOptionHandle clueOptionHandle;
    @Resource
    private MarketingActivityManagementOptionHandle marketingActivityManagementOptionHandle;
    @Resource
    private DistributorOptionHandle distributorOptionHandle;
    @Resource
    private DistributorContactOptionHandle distributorContactOptionHandle;
    @Resource
    private DistributorCommunicateOptionHandle distributorCommunicateOptionHandle;
    @Resource
    private OrderOptionHandle orderOptionHandle;
    @Resource
    private ReturnOptionHandle returnOptionHandle;
    @Resource
    private PromotionActivityManagementOptionHandle promotionActivityManagementOptionHandle;
    @Resource
    private DistributorAccountOptionHandle distributorAccountOptionHandle;
    @Resource
    private SalesOpportunityOptionHandle salesOpportunityOptionHandle;
    @Resource
    private CompetitorOptionHandle competitorOptionHandle;

    @PostConstruct
    public void init() {
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), customerOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.CONTRACT.getCode(), contractOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.PRODUCT.getCode(), productOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.PAYMENT.getCode(),paymentOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.SEQ_SEARCH.getCode(), productSerialOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.CLUE.getCode(), clueOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_MANAGEMENT.getCode(), distributorOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.MARKETING_ACTIVITY_MANAGEMENT.getCode(), marketingActivityManagementOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.PROMOTION_ACTIVITY_MANAGEMENT.getCode(), promotionActivityManagementOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_CONTACT.getCode(), distributorContactOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(), distributorCommunicateOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.ORDER.getCode(), orderOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.RETURN.getCode(), returnOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(), distributorAccountOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), salesOpportunityOptionHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.COMPETITOR.getCode(),competitorOptionHandle);
    }

    public AbstractOptionHandle getByBusinessType(Integer businessType, Integer saasMark) {
        if (Objects.equals(SaasMarkEnum.SAAS.getCode(), saasMark)) {
            return WEB_DATA_ANALYSIS_HANDLE_MAP.get(businessType);
        }
        return null;
    }
}
